package weeklyContest;

/**
 * @author zhangmin
 * @create 2021-09-19 10:32
 */
public class weeky_contest_259 {
    public int finalValueAfterOperations(String[] operations) {
        int x=0;
        for (String os:operations) {
            if (os.equals("++X")||os.equals("X++")){
                x++;
            }else {
                x--;
            }
        }
        return x;
    }

    public int sumOfBeauties(int[] nums) {
        int sum=0;
        int n=nums.length;
        boolean[] isChack2=new boolean[n];
        for (int i = 1; i <n-1 ; i++) {
            System.out.println("i="+i);
            if (i==1){
                isChack2[0]=chack(nums,0);
                isChack2[1]=chack2(nums,1);
                System.out.println("isChack2[0]="+isChack2[0]);
                System.out.println("isChack2[1]="+isChack2[1]);
            }
            if (nums[i-1]<nums[i]&&nums[i]<nums[i+1]){
                sum+=1;
                System.out.println("sum1="+sum);
            }
            if(isChack2[i-1]&&chack(nums,i)){
                sum+=1;
                isChack2[i]=true;
                System.out.println("sum2="+sum);
            }
        }
        return sum;
    }
    boolean chack(int[] nums,int i){
        for (int j = i+1; j < nums.length; j++) {
            if (nums[j]<=nums[i]){
                return false;
            }
        }
        return true;
    }
    boolean chack2(int[] nums,int i){
        for (int j = 0; j < i; j++) {
            for (int k = i+1; k <= nums.length-1; k++) {
                if (!(nums[j]<nums[i]&&nums[i]<nums[k])){
                   return false;
                }
            }
        }
        return true;
    }

    public int sumOfBeauties1(int[] nums) {
        int n=nums.length;
        int sum=0;
        int[] min=new int[n];
        //从后向前，存最小
        min[n-1]=nums[n-1];
        for (int i = n-2; i >=0 ; i--) {
            min[i]=Math.min(min[i+1],nums[i]);
        }
        //从前向后，存最大
        int[] max=new int[n];
        max[0]=nums[0];
        for (int i = 1; i < n-1; i++) {
            max[i]=Math.max(max[i-1],nums[i]);
            if (nums[i]>max[i-1]&&nums[i]<min[i+1]){
                sum+=2;
            }else if (nums[i]>nums[i-1]&&nums[i]<nums[i+1]){
                sum+=1;
            }
        }
        return sum;
    }




    public static void main(String[] args) {
        int[] nums=new int[]{1,2,3,4,5,7,8,9,10};
        weeky_contest_259 obj=new weeky_contest_259();
        System.out.println(obj.sumOfBeauties(nums));
    }
}
